import { AxiosPromise } from 'axios'
import request from '@/hooks/utils/http'

export class DeptService {

// 查询部门列表
    static listDept = (query?: DeptQuery) => {
        return request({
            url: '/system/dept/list',
            method: 'get',
            params: query
        });
    };

    /**
     * 通过deptIds查询部门
     * @param deptIds
     */
    static optionSelect = (deptIds: (number | string)[]): AxiosPromise<DeptVO[]> => {
        return request({
            url: '/system/dept/optionselect?deptIds=' + deptIds,
            method: 'get'
        });
    };

// 查询部门列表（排除节点）
    static listDeptExcludeChild = (deptId: string | number): AxiosPromise<DeptVO[]> => {
        return request({
            url: '/system/dept/list/exclude/' + deptId,
            method: 'get'
        });
    };

// 查询部门详细
    static getDept = (deptId: string | number): AxiosPromise<DeptVO> => {
        return request({
            url: '/system/dept/' + deptId,
            method: 'get'
        });
    };

// 查询部门下拉树结构
    static treeselect = (): AxiosPromise<DeptTreeVO[]> => {
        return request({
            url: '/system/dept/treeselect',
            method: 'get'
        });
    };

// 新增部门
    static addDept = (data: DeptForm) => {
        return request({
            url: '/system/dept',
            method: 'post',
            data: data
        });
    };

// 修改部门
    static updateDept = (data: DeptForm) => {
        return request({
            url: '/system/dept',
            method: 'put',
            data: data
        });
    };

// 删除部门
    static delDept = (deptId: number | string) => {
        return request({
            url: '/system/dept/' + deptId,
            method: 'delete'
        });
    };

}
/**
 * 部门查询参数
 */
export interface DeptQuery extends PageQuery {
    deptName?: string;
    deptCategory?: string;
    status?: number;
}

/**
 * 部门类型
 */
export interface DeptVO extends BaseEntity {
    id: number | string;
    parentName: string;
    parentId: number | string;
    children: DeptVO[];
    deptId: number | string;
    deptName: string;
    deptCategory: string;
    orderNum: number;
    leader: string;
    phone: string;
    email: string;
    status: string;
    delFlag: string;
    ancestors: string;
    menuId: string | number;
}

/**
 * 部门类型
 */
export interface DeptTreeVO extends BaseEntity {
    id: number | string;
    label: string;
    parentId: number | string;
    weight: number;
    children: DeptTreeVO[];
    disabled: boolean;
}

/**
 * 部门表单类型
 */
export interface DeptForm {
    parentName?: string;
    parentId?: number | string;
    children?: DeptForm[];
    deptId?: number | string;
    deptName?: string;
    deptCategory?: string;
    orderNum?: number;
    leader?: string;
    phone?: string;
    email?: string;
    status?: string;
    delFlag?: string;
    ancestors?: string;
}
